package alg20250214;

public class Text {
    public int minPathSum(int[][] grid) {
        //1 创建表
         int n = grid[0].length;
         int m = grid.length;
         int[][] dp = new int[m + 1][n + 1];
        //2 初始化
        for (int i = 1; i <= n; i++) {
            dp[0][i] = dp[i][0] = Integer.MAX_VALUE;
        }
        //3 填表
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i - 1][j - 1];
            }
        }
        //4 返回值
        return dp[m][n];
    }
}
